package com.example.controller;

import com.example.service.VCardService;
import com.example.utils.QRCodeUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@RestController
public class IndexController {

    @Resource
    private VCardService vCardService;

    /***
     * 生成二维码对应的文件内容
     * @param request
     * @param response
     */
    @RequestMapping(value = "/")
    public void getQR(HttpServletRequest request, HttpServletResponse response) {
        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            (new QRCodeUtil()).getQRCode(vCardService.create(), 300, 300, "https://img-home.csdnimg.cn/images/20201124032511.png", 50, 50, outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
